package com.wondersgroup.wuhan_demo.net;

import android.util.Log;

import com.zhy.http.okhttp.callback.Callback;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.lang.reflect.Type;

import okhttp3.Response;

/**
 * Created by janvei on 2016/11/15.
 */

public abstract class MyCallbackBean<T> extends Callback<T> {
    Type mType;


    public MyCallbackBean() {
//        mType = getSuperclassTypeParameter(getClass());
    }

//    static Type getSuperclassTypeParameter(Class<?> subclass) {
//        Type superclass = subclass.getGenericSuperclass();
//        if (superclass instanceof Class) {
//            throw new RuntimeException("Missing type parameter.");
//        }
//        ParameterizedType parameterized = (ParameterizedType) superclass;
//        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[1]);
//    }

    @Override
    public T parseNetworkResponse(Response response) throws Exception {
        Element rootElt=null;
        String content="";
        String responseStr=response.body().string();
        responseStr= responseStr.split("<return>")[1];
        responseStr=responseStr.split("</return>")[0];
        responseStr="<return>"+responseStr+"</return>";
        try {
            Document doc = null;
//            String xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><MessageHeader><code>0</code><desc>成功</desc></MessageHeader><List><Result><sysid>1234567894250530790020160626</sysid><mediCardId>310114000484203</mediCardId><mediCardType>2</mediCardType><checkType>1</checkType><yljgdm>42505307900</yljgdm><jyjcxm>临检111111</jyjcxm><bgrq>2016-06-26 00:00:00.0</bgrq><bgdh>123456789</bgdh><jc>工业区11111</jc></Result><Result><sysid>1234567894250530790020160626</sysid><mediCardId>310114000484203</mediCardId><mediCardType>2</mediCardType><checkType>1</checkType><yljgdm>42505307900</yljgdm><jyjcxm>临检</jyjcxm><bgrq>2016-06-26 00:00:00.0</bgrq><bgdh>123456789</bgdh><jc>工业区</jc></Result></List></Response>";
            doc = DocumentHelper.parseText(responseStr); // 将字符串转为XML
            Log.i("doc==",doc.asXML().toString());
             rootElt = doc.getRootElement(); // 获取根节点


//            Element msg= rootElt.element("message");

        } catch (Exception e) {
            e.printStackTrace();
        }

        return (T)rootElt;
    }

}